<template>
	<div class="equipTag-container">
		<el-dialog v-model="isShowDialog" :title="props.title" :width="700" draggable="">
			<el-form :model="ruleForm" ref="ruleFormRef" size="default" label-width="100px" :rules="rules">
				<el-row :gutter="35">

                    <el-col :xs="24" class="mb20">
						<el-form-item label="写入模式" prop="mode">
							<el-radio-group v-model="ruleForm.mode">
      <el-radio-button  label="0">地址</el-radio-button>
      <el-radio-button  label="1">点位名称</el-radio-button>
    
    </el-radio-group>
							
						</el-form-item>
						
					</el-col>
				
					<el-col :xs="24" class="mb20">
						<el-form-item label="关键字" prop="name">
							<el-input v-model="ruleForm.names" placeholder="关键字，以,隔开" clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24"  class="mb20">
						<el-form-item label="数据" prop="tagnum">
							<el-input v-model="ruleForm.datas" placeholder="数据，以,隔开" clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24"  class="mb20">
						<el-form-item label="点位" prop="tagnum">
							<el-input v-model="ruleForm.num" placeholder="点位" clearable />
							
						</el-form-item>
						
					</el-col>
					
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel" size="default">取 消</el-button>
					<el-button type="primary" @click="submit" size="default">写 入</el-button>
				</span>
			</template>
		</el-dialog>
		
	</div>
</template>

<script lang="ts" setup>
	import { ref } from "vue";
	import { ElMessage } from "element-plus";
	import type { FormRules } from "element-plus";
	import { WriteEquip } from "/@/api/main/equipTag";
	import equipInfoModal from '/@/views/main/equipInfo/component/equipInfoModal.vue'
	//父级传递来的参数
	var props = defineProps({
	title: {
	type: String,
	default: "",
	},
	});
	
	//父级传递来的函数，用于回调
	const emit = defineEmits(["reloadTable"]);
	const ruleFormRef = ref();
	const isShowDialog = ref(false);
	const ruleForm = ref<any>({});
		//自行删除非必填规则
		const rules = ref<FormRules>({
  names: [{required: true, message: '请输入名称！', trigger: 'blur',},],
  datas: [{required: true, message: '请输入数据！', trigger: 'blur',},],
  
 
});

// 打开弹窗
const openDialog = (row:any) => {
  

    ruleForm.value.mode=0;
    ruleForm.value.equipId=row.equipId;
    ruleForm.value.protobufType=row.protobufType;
  
  isShowDialog.value = true;

  
};

// 关闭弹窗
const closeDialog = () => {
  emit("reloadTable");
  isShowDialog.value = false;
};

// 取消
const cancel = () => {
  isShowDialog.value = false;
};

// 提交
const submit = async () => {
  ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
    if (isValid) {
      let values = ruleForm.value;
      if (ruleForm.value.equipId != undefined && ruleForm.value.equipId > 0) {

        await WriteEquip(values);
        closeDialog();
      } 
      
      
    } else {
      ElMessage({
        message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
        type: "error",
      });
    }
  });
};



//将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>




